package hmm;

import java.io.IOException;
import java.util.Map.Entry;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import Logging.Monitor;

import static hmm.Hmm.Smoothing.*;

public class HmmRealTest {
	
	Hmm test;
	
	@Before
	public void init() throws IOException {
		
		test = new Hmm(	new String[]{	"corpus_for_learning.txt", 
										"corpus_for_development.txt",
										"corpus_for_evaluation.txt"},
						LAPLACE);
		test.init();
	}
	
	@After
	public void end() {
		System.out.println("-----------");
	}
	
	//@Test
	public void testGetStatistics() throws IOException {
		
		Monitor.write(this, "Total num of tags:"+test.getNumOfTags());
		Monitor.write(this, "Total num of words:"+test.getNumWords());
		Monitor.write(this, "Total num of sentences:"+test.getNumSentences());
		Monitor.write(this, "-----------");
		int i=0;
		for(String tag : test.getAllTags()) {
			Monitor.write(this, tag+" at number:"+i++);
		}
		Monitor.write(this, "-----------");
		for(String base : test.getAllBaseWords()) {
			Monitor.write(this, base);
		}
		Monitor.write(this, "-----------");
		for(Entry<String,Integer> tag: test.getTagsToIndex().entrySet()) {
			Monitor.write(this, "Tag:"+tag.getKey()+" at index:"+tag.getValue());
		}
		Monitor.write(this, "-----------");
		for(Entry<String,Integer> tag: test.getBaseWordsToIndex().entrySet()) {
			Monitor.write(this, "Word:"+tag.getKey()+" at index:"+tag.getValue());
		}
		Monitor.write(this, "-----------");
	} 
	
	//@Test
	public void testTransionMatrix() throws IOException {
		
		double[][] A = test.getA();
		double[] count = new double[A.length];
		for (int i = 0; i < A.length; i++) {
			for (int j = 0; j < A[i].length; j++) {
				count[i]+=A[i][j];
				System.out.print(" "+A[i][j]+" ");
			}
			System.out.println();
		}
		System.out.println("-----------");
		for (int j = 0; j < A.length; j++) {
			System.out.print(" "+count[j]+" ");
		}
		System.out.println();
		System.out.println("-----------");
	}
	
	@Test
	public void testOutPutMatrix() throws IOException {

		double[][] B = test.getB();
		double[] count = new double[B.length];
		for (int i = 0; i < B.length; i++) {
			for (int j = 0; j < B[i].length; j++) {
				count[i]+=B[i][j];
				System.out.print(" "+B[i][j]+" ");
			}
			System.out.println();
		}
		System.out.println("-----------");
		for (int j = 0; j < B.length; j++) {
			System.out.print(" "+count[j]+" ");
		}
		System.out.println();
		System.out.println("-----------");
	}
	
	//@Test
	public void testInitMatrix() {
		
		double count= 0;
		double[] pi = test.getPi();
		for (int i = 0; i < pi.length; i++) {
			count+=pi[i];
			System.out.print(" "+pi[i]+" ");
		}
		System.out.println("\n"+count);
		System.out.println("-----------");
	}
	
}
